#include<iostream>
#include<string>
#include <fstream>
#include "bundle.h"
using namespace std;


int main(int argc, char* argv[])
{
    cout<<"argv[1]是源文件路径"<<endl;
    cout<<"argv[1]是压缩包路径"<<endl;

    if(argc<3) return -1;

    string ifilename = argv[1];
    string ofilename = argv[2];

    ifstream ifs;
    ifs.open(ifilename, std::ios::binary);   //打开源文件
    ifs.seekg(0, std::ios::end);   //跳转读写指针到末尾
    size_t fsize = ifs.tellg();    //获取末尾偏移量  -- 文件长度
    
    string body;
    body.resize(fsize);  //设置为文件大小
    ifs.read(&body[0], fsize);

    string packed = bundle::pack(bundle::LZIP, body);  //以lzip的格式压缩文件数据
    std::ofstream ofs;
    ofs.open(ofilename, std::ios::binary);  //二进制方式打开压缩包
    ofs.write(&packed[0], packed.size());  //将压缩后的数据写入压缩包

    
    ifs.close();
    ofs.close();

    return 0;
}